package com.caregiver.watch.business.user.model.vo;

import com.caregiver.watch.business.user.enums.UserChatMessageTypeEnum;
import com.caregiver.watch.business.user.model.po.UserChatMessage;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Description: 聊天消息
 * @Author 疆戟
 * @Date 2025/8/30 15:45
 * @Version 1.0
 */
@Data
@Schema(description = "聊天消息")
public class ChatMessageVo {

    /**
     * 消息ID
     */
    @Schema(description = "消息ID")
    private Long messageId;

    /**
     * 聊天窗口ID
     */
    @Schema(description = "聊天窗口ID")
    private Long chatWindowId;

    /**
     * 发送人ID
     */
    @Schema(description = "发送人ID")
    private Long senderId;

    /**
     * 消息类型
     */
    @Schema(description = "消息类型")
    private UserChatMessageTypeEnum messageType;
    /**
     * 消息内容
     */
    @Schema(description = "消息内容")
    private String content;

    /**
     * 发送时间
     */
    @Schema(description = "发送时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime sendTime;


    public static ChatMessageVo build(UserChatMessage userChatMessage) {
        ChatMessageVo chatMessageVo = new ChatMessageVo();
        chatMessageVo.chatWindowId = userChatMessage.getChatWindowId();
        chatMessageVo.messageId = userChatMessage.getMessageId();
        chatMessageVo.senderId = userChatMessage.getSenderId();
        chatMessageVo.messageType = UserChatMessageTypeEnum.pares(userChatMessage.getMessageType());
        chatMessageVo.content = userChatMessage.getContent();
        chatMessageVo.sendTime = userChatMessage.getCreateTime();
        return chatMessageVo;
    }
}
